package com.lich;

import com.alibaba.fastjson.JSON;

import java.util.HashMap;
import java.util.Map;

/**
 * 类型转换
 */
public class TypeConverter {
    private static Map<String, String> map = new HashMap<>();

    static {
        if (CommonUtils.isEmptyString(Constants.TYPE_CONVERTER_CONFIG)) {//配置为空使用默认配置
            map.put("varchar", "String");
            map.put("bpchar", "String");
            map.put("int2", "Short");
            map.put("int4", "Integer");
            map.put("int8", "Long");
            map.put("date", "Date");
            map.put("timestamp", "Date");
            map.put("numeric", "BigDecimal");
            map.put("float4", "Float");
            map.put("float8", "Double");
        } else {
            map = (Map<String, String>) JSON.parse(Constants.TYPE_CONVERTER_CONFIG);
        }
    }

    public static String getJavaType(String sqlType) {
        String javaType = map.get(sqlType);
        if (CommonUtils.isEmptyString(javaType)) {
            return "Object";
        } else {
            return javaType;
        }
    }
}
